package interview1719;

import leetcode.IDebug;
import leetcode.helper.H;
// 数学求根公式
public class View3 implements IDebug {

	public int[] missingTwo(int[] nums) {
		int len = nums.length + 2;
		long m = (len + 1) * len >> 1;
		long n = 0, aabb = 0;
		for (int i = 0; i <= len; i++) {
			if (i < nums.length) {
				int num = nums[i];
				m -= num;
				aabb += num * num;
			}
			n += i * i;
		}
		n -= aabb;
		n = (m * m - n)>>1;
		long a = this.aa(1, -m, n);
		return new int[] { (int) a, (int) (m - a) };
	}

	private long aa(long a, long b, long c) {
		return (-b + (long) Math.sqrt(b * b - ((a * c) << 2))) / (a << 1);
	}


	@Override
	public void debug4() {
		this.missingTwo(H.str2array3("[2]"));
		
	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub
		
	}
	public static void main(String[] args) {
		View3 v = new View3();
		v.debug4();
	}
}
